package com.igeek.boot.config;

import com.igeek.boot.entity.Car;
import com.igeek.boot.entity.Person;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

/**
 * @package com.igeek.boot.config
 * @Description 条件装配
 * @Author LittlePunk [296526219@qq.ccom]
 * @Version 2022.1
 * @Date 2023/12/5 15:23
 *
 * @Conditional条件装配
 * @ConditionalOn 如果有什么  就生效
 * @ConditionalOnMissing  如果没有什么  就生效
 *
 *
 * @ConditionalOnWebApplication
 * @ConditionalOnClass({Servlet.class,DispatcherServlet.class,WebMvcConfigurer.class})
 * @ConditionalOnMissingBean({WebMvcConfigurationSupport.class})
 * ...
 *
 * 使用场景：遵循 约定 > 配置  做出替换底层组件的操作 ,从而达到定制化开发
 *
 */
@Configuration
//@ConditionalOnMissingBean(Car.class)
//No qualifying bean of type 'com.igeek.boot.config.MyConfig3' available  IOC容器中存在Person类的bean
//@ConditionalOnMissingBean(Person.class)
public class MyConfig3 {

    @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
    @Bean(value = "p3")
    public Person person(){
        return new Person();
    }
}
